<?php
/**
 * This class is responsible for iterating over a Xapian 
 * result set.
 *
 * @author Rob Young <rob@roryoung.co.uk>
 * @package forage.engine.xapian
 */
class XapianMatchIterator implements Iterator
{
  private $matches;
  private $current;

  public function __construct(XapianMSet $matches)
  {
    $this->matches = $matches;
  }

  public function current()
  {
    return $this->current;
  }

  public function next()
  {
    $this->current->next();
  }

  public function key()
  {
    return $this->current->get_rank();
  }

  public function rewind()
  {
    $this->current = $this->matches->begin();
  }
  
  public function valid()
  {
    return !$this->current->equals($this->matches->end());
  }
}
